package com.asktgapp.user.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RatingBar;
import android.widget.TextView;

import com.asktgapp.JGTool.Utils;
import com.asktgapp.R;
import com.asktgapp.application.ApiUtil;
import com.asktgapp.application.Apiservice;
import com.asktgapp.application.MyApplication;
import com.asktgapp.architecture.retrofit.ApiException;
import com.asktgapp.architecture.retrofit.ApiResponseBody;
import com.asktgapp.architecture.rxjava.ExceptionHandle;
import com.asktgapp.base.BaseFragment;
import com.asktgapp.model.EvaluateLableNumVo;
import com.asktgapp.model.FreeAskSearchVO;
import com.asktgapp.model.IndustryInfoVO;
import com.asktgapp.model.UserEvaluateVO;
import com.asktgapp.modulebase.Constant;
import com.asktgapp.modulebase.common.adapter.BaseAdapter;
import com.asktgapp.modulebase.common.adapter.BaseViewHolder;
import com.asktgapp.modulebase.common.util.PreferencesUtil;
import com.asktgapp.modulebase.common.util.Util;
import com.asktgapp.user.activity.FreeAskAnswerDetailActivity;
import com.asktgapp.user.activity.IndustryInfoDetailActivity;
import com.asktgapp.user.activity.PhotoViewActivity;
import com.asktgapp.utils.ImageDisplayUtil;
import com.asktgapp.widget.RefreshRecyclerView;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 工程师详情页面中 点击更多页面
 */

public class EngineerDetailMoreFragment extends BaseFragment {
    private RefreshRecyclerView mRefreshRecyclerView;
    private RecyclerView mRecyclerView;
    private BaseAdapter questionAndAnswerAdapter, dynamicAdapter, commentAdapter;
    private int mPage = 1;
    private String mId;
    private int type;
    private LinearLayout noData;
    private RadioButton pj1, pj2, pj3, pjAll;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_search_result, container, false);
        return super.onCreateView(inflater, viewGroup, savedInstanceState);
    }

    @Override
    protected void initView(View rootView) {
        getBaseActivity().setBackNavigationIcon();
        mId = getActivity().getIntent().getStringExtra("engineerId");
        type = getActivity().getIntent().getIntExtra("type", 0);
        mRefreshRecyclerView = rootView.findViewById(R.id.recycle);
        noData = rootView.findViewById(R.id.noData);
        mRecyclerView = mRefreshRecyclerView.getRecyclerView();
        mRefreshRecyclerView.setLoadMoreAction(new RefreshRecyclerView.Action() {
            @Override
            public void onAction(int page) {
                mPage = page;
                getNetData(mPage);
            }
        });
        mRefreshRecyclerView.setRefreshAction(new RefreshRecyclerView.Action() {
            @Override
            public void onAction(int page) {
                mPage = page;
                getNetData(mPage);
            }
        });
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));

        mRecyclerView.setNestedScrollingEnabled(false);
        //type =0 评论更多 1 问答更多，2，动态（维修常识更多）

        if (type == 0) {
            pj1 = rootView.findViewById(R.id.pj1);
            pj2 = rootView.findViewById(R.id.pj2);
            pj3 = rootView.findViewById(R.id.pj3);
            pjAll = rootView.findViewById(R.id.pjAll);
            evaluateLable();
            //+++++++评价筛选开始
            RadioGroup pjGroup = rootView.findViewById(R.id.pjGroup);
            pjGroup.setVisibility(View.VISIBLE);
            pjGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    switch (checkedId) {
                        case R.id.pj1:
                            selLableEvaluateList(10);
                            break;
                        case R.id.pj2:
                            selLableEvaluateList(8);
                            break;
                        case R.id.pj3:
                            selLableEvaluateList(6);
                            break;
                        case R.id.pjAll:
                            mPage = 1;
                            getNetData(mPage);
                            break;
                    }
                }
            });
            //+++++++评价筛选结束

            commentAdapter = new BaseAdapter(getActivity()) {
                @Override
                public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
                    BaseViewHolder holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_engineer_detail_pj, parent, false),
                            new BaseViewHolder.Callbacks2() {
                                @SuppressLint("ResourceType")
                                @Override
                                public void bind(BaseViewHolder holder, Object data) {
                                    if (data instanceof UserEvaluateVO) {
                                        UserEvaluateVO bean = (UserEvaluateVO) data;
                                        ImageView head = holder.getView(R.id.userHead);
                                        RatingBar bar = holder.getView(R.id.rbNumber);
                                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), head, bean.getUserPic());
                                        holder.setText(R.id.userName, bean.getUserName());
                                        Date date = Util.StrToDate(bean.getAddTime(), "yyyy.MM.dd HH:mm:ss");
                                        String timeStr = Utils.getAskTime(date);
                                        holder.setText(R.id.commentTime, timeStr);
                                        String content = bean.getContent();
                                        if (TextUtils.isEmpty(content))
                                            content = "用户没有输入任何内容";
                                        holder.setText(R.id.commentContent, content);
                                        bar.setNumStars(bean.getSpeed());
                                        bar.setRating(bean.getSpeed());
                                        String pj;
                                        if (bean.getSpeed() <= 3) {
                                            pj = " (一般)";
                                        } else if (bean.getSpeed() <= 4)
                                            pj = " (满意)";
                                        else
                                            pj = " (非常满意)";
                                        holder.setText(R.id.tvPingJ, pj);

                                        if (!TextUtils.isEmpty(bean.getReplyContent())) {
                                            holder.getView(R.id.engineerHF).setVisibility(View.VISIBLE);
                                            holder.setText(R.id.engineerHF,
                                                    Html.fromHtml("<font color=\"#245290\">工程师回复：</font>"
                                                            + bean.getReplyContent()));
                                        }
                                    }
                                }

                                @Override
                                public void onItemClick(BaseViewHolder holder, View view, int position) {

                                }
                            });
                    return holder;
                }
            };
            mRecyclerView.setAdapter(commentAdapter);

        } else if (type == 1) {
            dynamicAdapter = new BaseAdapter(getActivity()) {

                @Override
                public int getItemViewType(int position) {
                    IndustryInfoVO bean = (IndustryInfoVO) dynamicAdapter.getData().get(position);
                    if (bean.getBannerList().size() > 1) {
                        return 20;
                    } else {
                        return 10;
                    }
                }

                @Override
                public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
                    BaseViewHolder holder;

                    if (viewType == 10) {
                        holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_industry_information, parent, false), new BaseViewHolder.Callbacks() {
                            @Override
                            public void bind(BaseViewHolder holder, Object data) {
                                ImageView img = holder.getView(R.id.iv_industry_img);
                                TextView title = holder.getView(R.id.tv_industry_title);
                                TextView time = holder.getView(R.id.tv_industry_time);
                                TextView comment = holder.getView(R.id.tv_industry_read_number);
                                TextView like = holder.getView(R.id.tv_industry_like);
                                if (data instanceof IndustryInfoVO) {
                                    IndustryInfoVO bean = (IndustryInfoVO) data;
                                    ImageDisplayUtil.LoadNetImage(img, getActivity(), bean.getBannerList().get(0));
                                    title.setText(bean.getTitle());
                                    time.setText(Utils.getDateYMD(bean.getAddTime()));
                                    comment.setText(String.valueOf(bean.getTalkNumber()));
                                    like.setText(String.valueOf(bean.getLikeNumber()));
                                    holder.setText(R.id.lookNumber, bean.getViewNumber());
                                }
                            }

                            @Override
                            public void onItemClick(View view, int position) {
                                IndustryInfoVO bean = (IndustryInfoVO) dynamicAdapter.getData().get(position);
                                Intent intent = new Intent(getActivity(), IndustryInfoDetailActivity.class);
                                intent.putExtra("id", bean.getId());
                                startActivity(intent);
                            }
                        });
                    } else {
                        holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_industry_information_three_image, parent, false), new BaseViewHolder.Callbacks() {
                            @Override
                            public void bind(BaseViewHolder holder, Object data) {

                                TextView title = holder.getView(R.id.tv_industry_title);
                                TextView time = holder.getView(R.id.tv_industry_time);
                                TextView comment = holder.getView(R.id.tv_industry_read_number);
                                TextView like = holder.getView(R.id.tv_industry_like);
                                ImageView ivQuestionImg1 = holder.getView(R.id.ivQuestionImg1);
                                ImageView ivQuestionImg2 = holder.getView(R.id.ivQuestionImg2);
                                ImageView ivQuestionImg3 = holder.getView(R.id.ivQuestionImg3);
                                if (data instanceof IndustryInfoVO) {

                                    IndustryInfoVO bean = (IndustryInfoVO) data;

                                    if (bean.getBannerList().size() > 2) {
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg1, getActivity(), bean.getBannerList().get(0));
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg2, getActivity(), bean.getBannerList().get(1));
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg3, getActivity(), bean.getBannerList().get(2));
                                    } else {
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg1, getActivity(), bean.getBannerList().get(0));
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg2, getActivity(), bean.getBannerList().get(1));
                                        ivQuestionImg3.setVisibility(View.GONE);
                                    }

                                    title.setText(bean.getTitle());
                                    time.setText(Utils.getDateYMD(bean.getAddTime()));
//                                comment.setText(String.valueOf(bean.getComment_number()));
//                                like.setText(String.valueOf(bean.getLike_number()));
                                    holder.setText(R.id.lookNumber, bean.getViewNumber());
                                }
                            }

                            @Override
                            public void onItemClick(View view, int position) {
                                IndustryInfoVO bean = (IndustryInfoVO) dynamicAdapter.getData().get(position);
                                Intent intent = new Intent(getActivity(), IndustryInfoDetailActivity.class);
                                intent.putExtra("id", bean.getId());
                                startActivity(intent);
                            }
                        });
                    }
                    return holder;
                }
            };
            mRecyclerView.setAdapter(dynamicAdapter);
        } else {
            questionAndAnswerAdapter = new BaseAdapter(getActivity()) {
                @Override
                public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
                    BaseViewHolder holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_free_ask_hot, parent, false),
                            new BaseViewHolder.Callbacks2() {
                                @Override
                                public void bind(BaseViewHolder holder, Object data) {
                                    if (data instanceof FreeAskSearchVO) {
                                        final FreeAskSearchVO bean = (FreeAskSearchVO) data;
                                        TextView allAnswer = holder.getView(R.id.allAnswer);
                                        ImageView askHead = holder.getView(R.id.iv_head_ask);
//                                    ImageView answerHead = holder.getView(R.id.iv_answer_head);
                                        ImageView ivZan = holder.getView(R.id.ivZan);
                                        ImageView ivQuestionImg1 = holder.getView(R.id.ivQuestionImg1);
                                        ImageView ivQuestionImg2 = holder.getView(R.id.ivQuestionImg2);
                                        ImageView ivQuestionImg3 = holder.getView(R.id.ivQuestionImg3);
                                        LinearLayout llQuestionImg = holder.getView(R.id.llQuestionImg);
                                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), askHead, bean.getUserPic());
                                        holder.setText(R.id.tvAskName, bean.getUsername());
                                        holder.setText(R.id.tvZan, bean.getProblemLikeNum());
                                        holder.setText(R.id.tv_answer, bean.getContent());
                                        if (TextUtils.isEmpty(bean.getLikeId()))
                                            ivZan.setImageResource(R.mipmap.zan_2);
                                        else {
                                            ivZan.setImageResource(R.mipmap.zan_1);
                                        }
                                        if (bean.getIsEngineer().equals("1")) {
                                            holder.getView(R.id.tvCommentType).setVisibility(View.VISIBLE);
                                        } else {
                                            holder.getView(R.id.tvCommentType).setVisibility(View.INVISIBLE);
                                        }
                                        llQuestionImg.setVisibility(View.VISIBLE);
                                        if (bean.getImgList().size() == 1) {
                                            ImageDisplayUtil.LoadNetImageWithUrl(ivQuestionImg1, getActivity(), bean.getImgList().get(0));
                                            ivQuestionImg2.setVisibility(View.GONE);
                                            ivQuestionImg3.setVisibility(View.GONE);
                                        } else if (bean.getImgList().size() == 2) {
                                            ImageDisplayUtil.LoadNetImageWithUrl(ivQuestionImg1, getActivity(), bean.getImgList().get(0));
                                            ImageDisplayUtil.LoadNetImageWithUrl(ivQuestionImg2, getActivity(), bean.getImgList().get(1));
                                            ivQuestionImg3.setVisibility(View.GONE);
                                        } else if (bean.getImgList().size() == 3) {
                                            ImageDisplayUtil.LoadNetImageWithUrl(ivQuestionImg1, getActivity(), bean.getImgList().get(0));
                                            ImageDisplayUtil.LoadNetImageWithUrl(ivQuestionImg2, getActivity(), bean.getImgList().get(1));
                                            ImageDisplayUtil.LoadNetImageWithUrl(ivQuestionImg3, getActivity(), bean.getImgList().get(2));
                                        } else {
                                            llQuestionImg.setVisibility(View.GONE);
                                        }

                                        ivQuestionImg1.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                PhotoViewActivity.statr(getActivity(), 0, (ArrayList<String>) bean.getImgList());
                                            }
                                        });
                                        ivQuestionImg2.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                PhotoViewActivity.statr(getActivity(), 1, (ArrayList<String>) bean.getImgList());
                                            }
                                        });
                                        ivQuestionImg3.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                PhotoViewActivity.statr(getActivity(), 2, (ArrayList<String>) bean.getImgList());
                                            }
                                        });

                                        Date date = Util.StrToDate(bean.getAddTime(), "yyyy.MM.dd HH:mm:ss");
                                        String timeStr = Utils.getAskTime(date);
                                        holder.setText(R.id.addTime, timeStr);

                                        if (bean.getAnswerList().size() > 0) {
                                            holder.getView(R.id.llAnswerComment).setVisibility(View.VISIBLE);
                                            holder.setText(R.id.answerNumber, bean.getAnswerNum() + " 回复");
//                                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), answerHead, bean.getUserPic());
                                            //判断是否工程师
                                            if (bean.getAnswerList().get(0).getIsProjector().equals("1")) {
                                                holder.getView(R.id.tvCommentType).setVisibility(View.VISIBLE);
                                            } else {
                                                holder.getView(R.id.tvCommentType).setVisibility(View.INVISIBLE);
                                            }
                                            holder.setText(R.id.tvAnswerName, bean.getAnswerList().get(0).getUsername1());

                                            holder.setText(R.id.tvAnswerContent, bean.getAnswerList().get(0).getContent());
                                            if (bean.getAnswerList().size() > 1) {
                                                holder.getView(R.id.llAnswer2).setVisibility(View.VISIBLE);
                                                holder.setText(R.id.tvAnswerName2, bean.getAnswerList().get(1).getUsername1());
                                                holder.setText(R.id.tvAnswerContent2, bean.getAnswerList().get(1).getContent());
                                                //判断是否工程师
                                                if (bean.getAnswerList().get(1).getIsProjector().equals("1")) {
                                                    holder.getView(R.id.tvCommentType2).setVisibility(View.VISIBLE);
                                                } else {
                                                    holder.getView(R.id.tvCommentType2).setVisibility(View.INVISIBLE);
                                                }
                                            } else {
                                                holder.getView(R.id.llAnswer2).setVisibility(View.GONE);
                                            }

                                        } else {
                                            holder.setText(R.id.answerNumber, "无回复");
                                            holder.getView(R.id.llAnswerComment).setVisibility(View.GONE);
                                        }
                                        allAnswer.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty( bean.getId(),getContext());
                                            }
                                        });

                                        holder.getView(R.id.tvAnswerName).setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                SkipToEngineerDetail(getActivity(), String.valueOf(bean.getAnswerList().get(0).getId()));
                                            }
                                        });
                                        holder.getView(R.id.zan).setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                //点赞接口
                                                if (TextUtils.isEmpty(bean.getLikeId())) {
                                                    dealZan(bean.getId(), "1", bean, 3);
                                                } else {
                                                    dealZan(bean.getId(), "0", bean, 3);
                                                }
                                                index = questionAndAnswerAdapter.getItemIndex(bean);
                                            }
                                        });
                                    }
                                }

                                @Override
                                public void onItemClick(BaseViewHolder holder, View view, int position) {
                                    FreeAskSearchVO b = (FreeAskSearchVO) questionAndAnswerAdapter.getData(position);
                                    FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty( b.getId(),getContext());
                                }
                            });


                    return holder;
                }
            };
            mRecyclerView.setAdapter(questionAndAnswerAdapter);
        }
    }

    @Override
    public void loadData() {
        visibleLoading();
        getNetData(mPage);

    }

    //获取评价标签
    private void evaluateLable() {

        Apiservice apiservice = ApiUtil.getInstance().create();
        HashMap params = new HashMap();
        params.put("userId", mId);
        params.put("deviceId", Utils.getDeviceId(MyApplication.getInstance()));
        params.put("platform", Constant.ANDROID_CHANNEL);
        Call<ApiResponseBody<EvaluateLableNumVo>> call = apiservice.evaluateLable(params);
        call.enqueue(new Callback<ApiResponseBody<EvaluateLableNumVo>>() {
            @Override
            public void onResponse(Call<ApiResponseBody<EvaluateLableNumVo>> call, Response<ApiResponseBody<EvaluateLableNumVo>> response) {
                if (response.isSuccessful()) {
                    EvaluateLableNumVo data = response.body().getResult();
                    pj3.setText("一般 (" + data.getLowSatisfaction() + ")");
                    pj2.setText("满意 (" + data.getSecondarySatisfaction() + ")");
                    pj1.setText("非常满意 (" + data.getVerySatisfaction() + ")");
                    pjAll.setText("全部 (" + data.getTotalNum() + ")");
                }
            }

            @Override
            public void onFailure(Call<ApiResponseBody<EvaluateLableNumVo>> call, Throwable t) {
            }
        });
    }


    private void getNetData(final int mPage) {

        if (type == 0) {
            Apiservice apiservice = ApiUtil.getInstance().create();
            HashMap params = new HashMap();
            params.put("page", mPage);
            params.put("userId", mId);
            params.put("more", 1);
            Call<ApiResponseBody<List<UserEvaluateVO>>> call1 = apiservice.selEvaluateList(params);
            call1.enqueue(new Callback<ApiResponseBody<List<UserEvaluateVO>>>() {
                @Override
                public void onResponse(Call<ApiResponseBody<List<UserEvaluateVO>>> call, Response<ApiResponseBody<List<UserEvaluateVO>>> response) {
                    inVisibleLoading();
                    mRefreshRecyclerView.endPage();
                    if (response.isSuccessful()) {
                        List<UserEvaluateVO> list = response.body().getResult();
//                        if(list!=null&&list.size()>0){
//                            commentAdapter.setData(list);
//                            mRefreshRecyclerView.showNoMore();
//                        }
                        noData.setVisibility(View.GONE);
                        mRefreshRecyclerView.setVisibility(View.VISIBLE);
                        if (mPage == 1) {
                            if (list != null && list.size() == 0) {
                                visibleNoData();
                            } else {
                                commentAdapter.setData(list);
                                mRefreshRecyclerView.showNextMore(mPage);
                            }
                        } else {
                            if (list.size() == 0) {
                                mRefreshRecyclerView.showNoMore();
                            } else {
                                commentAdapter.addData(BaseAdapter.AddType.LASE, list);
                                mRefreshRecyclerView.showNextMore(mPage);
                            }
                        }
                    } else {
                        showTost(response.raw().message(), 1);
                    }
                }

                @Override
                public void onFailure(Call<ApiResponseBody<List<UserEvaluateVO>>> call, Throwable t) {
                    inVisibleLoading();
                    mRefreshRecyclerView.endPage();

                    ApiException apiException = ExceptionHandle.handleException(t);
                    if (apiException.isTokenInvalid()) {
                        showUnLoginSnackbar();
                    } else if (apiException.isNetConnected()) {
                        showSetNetworkSnackbar();
                    } else {
                        showTost(apiException.getMessage(), 0);
                    }

                }
            });
            addSubscription(call1);
        } else if (type == 1) {
            Apiservice apiservice = ApiUtil.getInstance().create();
            HashMap params = new HashMap();
            params.put("page", mPage);
            params.put("userId", mId);
            params.put("more", 1);
            Call<ApiResponseBody<List<IndustryInfoVO>>> call2 = apiservice.selInformationList(params);
            call2.enqueue(new Callback<ApiResponseBody<List<IndustryInfoVO>>>() {
                @Override
                public void onResponse(Call<ApiResponseBody<List<IndustryInfoVO>>> call, Response<ApiResponseBody<List<IndustryInfoVO>>> response) {
                    inVisibleLoading();
                    mRefreshRecyclerView.endPage();
                    if (response.isSuccessful()) {
                        List<IndustryInfoVO> list = response.body().getResult();
//                        if(list!=null&&list.size()>0){
//                            dynamicAdapter.setData(list);
//                            mRefreshRecyclerView.showNoMore();
//                        }
                        if (mPage == 1) {
                            if (list != null && list.size() == 0) {
                                visibleNoData();
                            } else {
                                dynamicAdapter.setData(list);
                                mRefreshRecyclerView.showNextMore(mPage);
                            }
                        } else {
                            if (list.size() == 0) {
                                mRefreshRecyclerView.showNoMore();
                            } else {
                                dynamicAdapter.addData(BaseAdapter.AddType.LASE, list);
                                mRefreshRecyclerView.showNextMore(mPage);
                            }
                        }
                    } else {
                        showTost(response.raw().message(), 0);
                    }
                }

                @Override
                public void onFailure(Call<ApiResponseBody<List<IndustryInfoVO>>> call, Throwable t) {
                    mRefreshRecyclerView.endPage();
                    inVisibleLoading();
                    ApiException apiException = ExceptionHandle.handleException(t);
                    if (apiException.isTokenInvalid()) {
                        showUnLoginSnackbar();
                    } else if (apiException.isNetConnected()) {
                        showSetNetworkSnackbar();
                    } else {
                        showTost(apiException.getMessage(), 0);
                    }

                }
            });
            addSubscription(call2);
        } else {
            Apiservice apiservice = ApiUtil.getInstance().create();
            HashMap params = new HashMap();
            params.put("page", mPage);
            params.put("userId", mId);
            params.put("type", 1);
            params.put("isEngineer", 1);
            Call<ApiResponseBody<List<FreeAskSearchVO>>> call3 = apiservice.selMyProblemList(params);
            call3.enqueue(new Callback<ApiResponseBody<List<FreeAskSearchVO>>>() {
                @Override
                public void onResponse(Call<ApiResponseBody<List<FreeAskSearchVO>>> call, Response<ApiResponseBody<List<FreeAskSearchVO>>> response) {
                    inVisibleLoading();
                    mRefreshRecyclerView.endPage();
                    if (response.isSuccessful()) {
                        List<FreeAskSearchVO> list = response.body().getResult();
                        if (mPage == 1) {
                            if (list.size() == 0) {
                                visibleNoData();
                            } else {
                                questionAndAnswerAdapter.setData(list);
                                mRefreshRecyclerView.showNextMore(mPage);
                            }
                        } else {
                            if (list.size() == 0) {
                                mRefreshRecyclerView.showNoMore();
                            } else {
                                questionAndAnswerAdapter.addData(BaseAdapter.AddType.LASE, list);
                                mRefreshRecyclerView.showNextMore(mPage);
                            }
                        }
                    }
                }

                @Override
                public void onFailure(Call<ApiResponseBody<List<FreeAskSearchVO>>> call, Throwable t) {
                    inVisibleLoading();
                    mRefreshRecyclerView.endPage();
                    ApiException apiException = ExceptionHandle.handleException(t);
                    if (apiException.isTokenInvalid()) {
                        showUnLoginSnackbar();
                    } else if (apiException.isNetConnected()) {
                        showSetNetworkSnackbar();
                    } else {
                        showTost(apiException.getMessage(), 0);
                    }

                }
            });
        }
    }

    private void selLableEvaluateList(int Satisfaction) {

        if (type == 0) {
            Apiservice apiservice = ApiUtil.getInstance().create();
            HashMap params = new HashMap();
            params.put("satisfaction", Satisfaction);
            params.put("userId", mId);
            Call<ApiResponseBody<List<UserEvaluateVO>>> call1 = apiservice.selLableEvaluateList(params);
            call1.enqueue(new Callback<ApiResponseBody<List<UserEvaluateVO>>>() {
                @Override
                public void onResponse(Call<ApiResponseBody<List<UserEvaluateVO>>> call, Response<ApiResponseBody<List<UserEvaluateVO>>> response) {
                    inVisibleLoading();
                    mRefreshRecyclerView.endPage();
                    if (response.isSuccessful()) {
                        List<UserEvaluateVO> list = response.body().getResult();
//                        if(list!=null&&list.size()>0){
//                            commentAdapter.setData(list);
//                            mRefreshRecyclerView.showNoMore();
//                        }
                        if (list != null && list.size() == 0) {
                            noData.setVisibility(View.VISIBLE);
                            mRefreshRecyclerView.setVisibility(View.GONE);
                        } else {
                            noData.setVisibility(View.GONE);
                            mRefreshRecyclerView.setVisibility(View.VISIBLE);
                            commentAdapter.setData(list);
                            mRefreshRecyclerView.showNoMore();
                        }
                    } else {
                        showTost(response.raw().message(), 1);
                    }
                }

                @Override
                public void onFailure(Call<ApiResponseBody<List<UserEvaluateVO>>> call, Throwable t) {
                    inVisibleLoading();
                    mRefreshRecyclerView.endPage();

                    ApiException apiException = ExceptionHandle.handleException(t);
                    if (apiException.isTokenInvalid()) {
                        showUnLoginSnackbar();
                    } else if (apiException.isNetConnected()) {
                        showSetNetworkSnackbar();
                    } else {
                        showTost(apiException.getMessage(), 0);
                    }

                }
            });
            addSubscription(call1);
        }
    }

    private int index = -1;

    //点赞接口
    private void dealZan(String id, final String temp, final FreeAskSearchVO bean, int type) {
        if (Util.isEmpty(PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID))) {
            showTost("未登录，不能点赞！请先登录", 1);
            return;
        }
        Apiservice apiservice = ApiUtil.getInstance().create();
        HashMap params = new HashMap();

        params.put("temp", temp);
        params.put("type", type);
        params.put("id", id);
        params.put("userid", PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID));
//        showProgress(getClass().getSimpleName());
        Call<ApiResponseBody> call = apiservice.doLike(params);
        call.enqueue(new Callback<ApiResponseBody>() {
            @Override
            public void onResponse(Call<ApiResponseBody> call, Response<ApiResponseBody> response) {
//                dismissProgress();
                if (response.isSuccessful()) {
                    int num = Integer.valueOf(bean.getProblemLikeNum());
                    if (temp.equals("1")) {
                        num++;
                        bean.setLikeId("13");
                    } else {
                        num--;
                        bean.setLikeId(null);
                    }
                    bean.setProblemLikeNum(String.valueOf(num));
                    questionAndAnswerAdapter.update(bean, index);
                } else {
                    showTost(response.raw().message(), 0);
                }
            }

            @Override
            public void onFailure(Call<ApiResponseBody> call, Throwable t) {
//                dismissProgress();
                ApiException exception = ExceptionHandle.handleException(t);
                if (exception.isTokenInvalid()) {
                    showUnLoginSnackbar();
                } else if (exception.isNetConnected()) {
                    showSetNetworkSnackbar();
                } else {
                    showTost(exception.getMessage(), 1);
                }
            }
        });

    }

}
